namespace Webbness.Generator.CodeDom.Sql

import System
import System.Text
import Neo.Generator.Core
import Neo.MetaModel

class SqlTable:
	
	_columns as List
	_constraints as List
	_comments as List
	
	def constructor():
		_columns = List()
		_constraints = List()
		_comments = List()
		
	def constructor(entity as Entity):
		self()
		_entity = entity
		_tableName = entity.TableName
	
	def constructor(entity as Entity, action as ActionType):
		self(entity)
		_action = action
		
	def AddComment(comment as string):
		_comments.Add(comment)
	
	SqlComments as string:
		get:
			return _comments.Join(' ')
	
	[property(TableName)]
	_tableName as string
	
	[getter(Entity)]
	_entity as Entity
	
	[property(Action)]
	_action as ActionType
	
	def AddColumn(attrib as SqlColumn):
		_columns.Add(attrib)
		
	def AddColumn(colName as string, action as ActionType):
		ea = EntityAttribute()
		ea.ColumnName = colName
		AddColumn(SqlColumn(ea, action))
		
	def CreateColumn(colName as string) as SqlColumn:
		ea = EntityAttribute()
		ea.ColumnName = colName
		return SqlColumn(ea)
	
	def AddConstraint(attrib as SqlConstraint):
		_constraints.Add(attrib)
	
	Columns as (SqlColumn):
		get:
			return _columns.ToArray(typeof(SqlColumn))
			
	Constraints as (SqlConstraint):
		get:
			return _constraints.ToArray(typeof(SqlConstraint))
